<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>28.禁止constructor被遍历</title>
</head>

<body>
</body>

<script>

  function User () { }
  User.prototype.name = function () {
    console.log('user.name');
  }



  function Admin () { }
  // 使用 Object.oncreate 创建的对象是全新的，它的构造函数就会被遍历出来
  Admin.prototype = Object.create(User.prototype);
  // 构造函数不该被遍历出来需要修改属性禁止构造函数被遍历
  Object.defineProperty(Admin.prototype, "constructor", {
    value: Admin,
    enumerable: false //禁止遍历
  });
  //  不赋值 则constructor丢失，返回User构造函数
  Admin.prototype.constructor = Admin;
  Admin.prototype.role = function () {
    console.log('admin role');
  };
  let a = new Admin();

  for (let key in a) {
    console.log(key);
  }
</script>

</html>